package com.hzhc.controller.sysmanage;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzhc.annotation.SysTemLog;
import com.hzhc.common.BaseController;
import com.hzhc.entity.VersionContent;
import com.hzhc.entity.VersionInfo;
import com.hzhc.enumBean.ResultUtilCodeEnum;
import com.hzhc.service.VersionContentService;
import com.hzhc.service.VersionInfoService;
import com.hzhc.utils.ResultUtil;
import com.hzhc.vo.VersionContentVo;
import com.hzhc.vo.VersionInfoVo;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 版本维护
 *
 * @author 功不唐捐
 * @since 2024-04-07
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/versionInfo")
public class VersionInfoController extends BaseController {

    private final VersionInfoService versionInfoService;
    private final VersionContentService versionContentService;

    /**
     * 查询更新日志分页列表
     */
    @RequestMapping("/getVersionInfoPage")
    public ResultUtil<List<VersionInfoVo>> getVersionInfoList(@RequestBody VersionInfoVo vo) {
        Page<VersionInfoVo> page = new Page<>(vo.getPageIndex(), vo.getPageSize());
        List<VersionInfoVo> list = versionInfoService.getVersionInfoPage(page, vo);
        return ResultUtil.build(list,page.getTotal(), page.getPages(), ResultUtilCodeEnum.SUCCESS);
    }

    /**
     * 新增更新日志
     */
    @PostMapping("/addVersionInfo")
    @SysTemLog(operModul = "系统管理-更新日志", operType = "新增", operDesc = "更新日志新增功能", modular = "PC")
    public ResultUtil<T> addVersionInfo(@RequestBody VersionInfo vo) {
        return versionInfoService.addVersionInfo(vo);
    }

    /**
     * 修改更新日志
     */
    @PostMapping("/updateVersionInfo")
    @SysTemLog(operModul = "系统管理-更新日志", operType = "修改", operDesc = "更新日志修改功能", modular = "PC")
    public ResultUtil<T> updateVersionInfo(@RequestBody VersionInfo vo) {
        return versionInfoService.updateVersionInfo(vo);
    }

    /**
     * 更新日志删除
     */
    @RequestMapping("/deleteVersionInfo/{id}")
    @SysTemLog(operModul = "版本控制-更新日志", operType = "删除", operDesc = "更新日志删除功能", modular = "PC")
    public ResultUtil<T> deleteVersionInfo(@PathVariable("id") Long id) {
        return versionInfoService.deleteVersionInfo(id);
    }

    /**
     * 查询日志详情分页列表
     */
    @RequestMapping("/getVersionContentPage")
    public ResultUtil<List<VersionContentVo>> getVersionContentPage(@RequestBody VersionContentVo vo) {
        Page<VersionContentVo> page = new Page<>(vo.getPageIndex(), vo.getPageSize());
        List<VersionContentVo> list = versionContentService.getVersionContentPage(page, vo);
        return ResultUtil.build(list,page.getTotal(), page.getPages(), ResultUtilCodeEnum.SUCCESS);
    }

    /**
     * 新增日志详情
     */
    @PostMapping("/addVersionContent")
    @SysTemLog(operModul = "系统管理-日志详情", operType = "新增", operDesc = "日志详情新增功能", modular = "PC")
    public ResultUtil<T> addVersionContent(@RequestBody VersionContent vo) {
        return versionContentService.addVersionContent(vo);
    }

    /**
     * 修改日志详情
     */
    @PostMapping("/updateVersionContent")
    @SysTemLog(operModul = "系统管理-日志详情", operType = "修改", operDesc = "日志详情修改功能", modular = "PC")
    public ResultUtil<T> updateVersionContent(@RequestBody VersionContent vo) {
        return versionContentService.updateVersionContent(vo);
    }

    /**
     * 日志详情删除
     */
    @RequestMapping("/deleteVersionContent/{id}")
    @SysTemLog(operModul = "版本控制-更新日志", operType = "删除", operDesc = "更新日志删除功能", modular = "PC")
    public ResultUtil<T> deleteVersionContent(@PathVariable("id") Long id) {
        return versionContentService.deleteVersionContent(id);
    }

    /**
     * 更新日志
     */
    @PostMapping("/updateLogs")
    public ResultUtil<List<VersionInfoVo>> updateLogs(@RequestBody VersionInfo vo) {
        ResultUtil<List<VersionInfoVo>> result = versionInfoService.getVersionInfo(vo);
        return result;
    }

}
